package algotithm.leetcode.dp.test322;

import java.util.Arrays;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/27-23:38
 * @Title 322. 零钱兑换
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] coins = {1,2,5};
        int amount = 11;
        int change = solution.coinChange(coins, amount);
        System.out.println(change);
    }

    public int coinChange(int[] coins, int amount) {
        int[] dp = new int[amount + 1];
        int max = amount + 1;
        Arrays.fill(dp,max);
        dp[0] = 0;
        for (int i = 1; i <= amount; i++) {
            for (int j = 0; j < coins.length; j++) {
                if (coins[j] <= i) {
                    dp[i] = Math.min(dp[i],dp[i-coins[j]] + 1);
                }
            }
        }
        return dp[amount]  > amount ? -1 : dp[amount];
    }

}
